home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / corelib / ncbierr.h < prev    next >
Text File  |  1996-07-05  |  13KB  |  399 lines

  1. /*   ncbierr.h
  2. * ===========================================================================
  3. *
  4. *                            PUBLIC DOMAIN NOTICE
  5. *               National Center for Biotechnology Information
  6. *
  7. *  This software/database is a "United States Government Work" under the
  8. *  terms of the United States Copyright Act.  It was written as part of
  9. *  the author's official duties as a United States Government employee and
  10. *  thus cannot be copyrighted.  This software/database is freely available
  11. *  to the public for use. The National Library of Medicine and the U.S.
  12. *  Government have not placed any restriction on its use or reproduction.
  13. *
  14. *  Although all reasonable efforts have been taken to ensure the accuracy
  15. *  and reliability of the software and data, the NLM and the U.S.
  16. *  Government do not and cannot warrant the performance or results that
  17. *  may be obtained by using this software or data. The NLM and the U.S.
  18. *  Government disclaim all warranties, express or implied, including
  19. *  warranties of performance, merchantability or fitness for any particular
  20. *  purpose.
  21. *
  22. *  Please cite the author in any work or product based on this material.
  23. *
  24. * ===========================================================================
  25. *
  26. * File Name:  ncbierr.c
  27. *
  28. * Author:  Schuler, Sirotkin (UserErr stuff)
  29. *
  30. * Version Creation Date:   9-19-91
  31. *
  32. * $Revision: 2.22 $
  33. *
  34. * File Description:  Error handling functions
  35. *
  36. * Modifications:
  37. * --------------------------------------------------------------------------
  38. * Date      Name        Description of modification
  39. * --------  ----------  -----------------------------------------------------
  40. * 12-10-93  Schuler     Major Revision.  New APIs include:  ErrPostEx, 
  41. *                       ErrSetMessageLevel, ErrSetFatalLevel, 
  42. * ==========================================================================
  43. */
  44.  
  45. #ifndef _NCBIERR_
  46. #define _NCBIERR_
  47.  
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51.  
  52. #include <ncbilcl.h>
  53. #include <ncbistd.h>
  54. #include <ncbimisc.h>
  55.  
  56.  
  57. #ifndef THIS_FILE
  58. #define THIS_FILE  __FILE__
  59. #endif
  60. #ifndef THIS_MODULE
  61. #define THIS_MODULE  NULL
  62. #endif
  63.  
  64. #ifdef _DEBUG
  65. #define DBFLAG 1
  66. #else
  67. #define DBFLAG 0
  68. #endif
  69.  
  70.  
  71. #define E_NoMemory      1
  72. #define E_File          2
  73. #define E_FOpen     3
  74. #define E_FRead     4
  75. #define E_FWrite    5
  76. #define E_CdEject   9
  77. #define E_Math          4
  78. #define E_SGML          3
  79. #define E_Programmer  999
  80.  
  81.  
  82. struct _ErrDesc;     /** Error Descriptor **/
  83. typedef struct _ErrDesc ErrDesc;
  84. #if defined(DCLAP) && !defined(WIN16)
  85. typedef const FAR void *ErrDescPtr;
  86. #else
  87. typedef const FAR *ErrDescPtr;
  88. #endif
  89.  
  90. struct _ErrOpts;      /** Error Options **/
  91. typedef struct _ErrOpts ErrOpts;
  92. #if defined(DCLAP) && !defined(WIN16)
  93. typedef const FAR void *ErrOptsPtr;
  94. #else
  95. typedef const FAR *ErrOptsPtr;
  96. #endif
  97.  
  98. struct _ErrMsgRoot;  /** Root of error message tree **/
  99. typedef struct _ErrMsgRoot  ErrMsgRoot;
  100. typedef const ErrMsgRoot FAR *ErrMsgRootPtr;
  101.  
  102. struct _ErrMsgNode;  /** Node in error message tree **/
  103. typedef struct _ErrMsgNode ErrMsgNode;
  104. typedef const ErrMsgNode FAR *ErrMsgNodePtr;
  105.  
  106.  
  107. /* prototype for user-supplied error handler */
  108. typedef int (LIBCALLBACK *ErrHookProc) PROTO((const ErrDesc *err));
  109.  
  110. /***************************************************************************\
  111. |                           POSTING AN ERROR                                |
  112. \***************************************************************************/
  113.  
  114. enum _ErrSev { SEV_NONE=0, SEV_INFO, SEV_WARNING, SEV_ERROR, SEV_FATAL };
  115. typedef enum _ErrSev ErrSev;
  116.  
  117. #define SEV_MIN  SEV_INFO
  118. #define SEV_MAX (SEV_FATAL+1)
  119.  
  120. void CDECL Nlm_ErrPost VPROTO((int ctx, int code, const char *fmt, ...));
  121. int CDECL Nlm_ErrPostEx VPROTO((ErrSev sev, int lev1, int lev2, const char *fmt, ...));
  122. int LIBCALL Nlm_ErrPostStr PROTO((ErrSev sev, int lev1, int lev2, const char *str));
  123. void CDECL Nlm_ErrLogPrintf VPROTO((const char *fmt, ...));
  124. void LIBCALL Nlm_ErrLogPrintStr PROTO((const char *str));
  125. int LIBCALL Nlm_ErrSetContext PROTO((const char *ctx, const char *fn, int ln, int db));
  126.  
  127. #define ErrPost    \
  128.     (Nlm_ErrSetContext(THIS_MODULE,THIS_FILE,__LINE__,DBFLAG)) ? (void)0 : \
  129.     Nlm_ErrPost
  130.  
  131. #define ErrPostEx    \
  132.     (Nlm_ErrSetContext(THIS_MODULE,THIS_FILE,__LINE__,DBFLAG)) ? 0 : \
  133.     Nlm_ErrPostEx
  134.  
  135. #define ErrPostStr  \
  136.     (Nlm_ErrSetContext(THIS_MODULE,THIS_FILE,__LINE__,DBFLAG)) ? 0 : \
  137.     Nlm_ErrPostStr
  138.  
  139. #define ErrLogPrintf  Nlm_ErrLogPrintf
  140. #define ErrLogPrintStr Nlm_ErrLogPrintStr
  141.  
  142. /***************************************************************************\
  143. |                     FETCHING AND REPORTING ERRORS                         |
  144. \***************************************************************************/
  145. #define ERRTEXT_MAX  512
  146. #define CODESTR_MAX  64
  147. #define MODSTR_MAX   32
  148. #define SRCFILE_MAX  92
  149.  
  150. struct _ErrDesc 
  151. {
  152.     short severity;
  153.     short context;  /* OBSOLETE */
  154.     char  module[MODSTR_MAX];
  155.     int   errcode;
  156.     int   subcode;
  157.     char  codestr[CODESTR_MAX];
  158.     char  srcfile[SRCFILE_MAX];
  159.     int   srcline;
  160.     char  errtext[ERRTEXT_MAX];
  161.     const ValNode *userstr;
  162.     const ErrMsgRoot *root;
  163.     const ErrMsgNode *node;
  164. };
  165.  
  166. int LIBCALL Nlm_ErrFetch PROTO((ErrDesc FAR *err));
  167. int LIBCALL Nlm_ErrCopy PROTO((ErrDesc FAR *err));
  168. void LIBCALL Nlm_ErrClear PROTO((void));
  169. int LIBCALL Nlm_ErrShow PROTO((void));
  170.  
  171. #define ErrShow     Nlm_ErrShow
  172. #define ErrFetch    Nlm_ErrFetch
  173. #define ErrClear    Nlm_ErrClear
  174. #define ErrCopy     Nlm_ErrCopy
  175. #define ErrPeek()   Nlm_ErrCopy(NULL)
  176.  
  177.  
  178. /***************************************************************************\
  179. |                           MESSAGE FILE SUPPORT                            |
  180. \***************************************************************************/
  181. struct _ErrMsgRoot
  182.     ErrMsgRoot *next;
  183.     ErrMsgNode *list;
  184.     const char *name;
  185.     /*unsigned int busy :1;*/
  186.     /*unsigned int not_avail :1;*/
  187. };
  188.  
  189. struct _ErrMsgNode
  190.     ErrMsgNode *next;
  191.     ErrMsgNode *list;
  192.     const char *name;
  193.     int code;
  194.     int sev;
  195.     long cofs, clen;
  196.     long tofs, tlen;
  197.     const char *cstr;    
  198.     const char *tstr;
  199. };
  200.  
  201. /** Don't use these functions **/
  202. ErrMsgRootPtr LIBCALL ErrGetMsgRoot PROTO((const char *context));
  203. const char* LIBCALL ErrGetExplanation PROTO((ErrMsgRootPtr idx, ErrMsgNodePtr item));
  204.  
  205. /***************************************************************************\
  206. |                             CUSTOMIZATION                                 |
  207. \***************************************************************************/
  208. struct _ErrOpts
  209. {
  210.     unsigned long flags;
  211.     short log_level;
  212.     short msg_level;
  213.     short die_level;
  214.     short actopt;
  215.     short logopt;
  216. };
  217.  
  218. typedef Nlm_Uint1 ErrStrId;
  219.  
  220. int LIBCALL Nlm_ErrSetLogfile PROTO((const char *filename, unsigned long flags));
  221. ErrHookProc LIBCALL Nlm_ErrSetHandler PROTO((ErrHookProc));
  222. ErrStrId LIBCALL Nlm_ErrUserInstall PROTO((const char *msg, ErrStrId magic_cookie));
  223. Nlm_Boolean LIBCALL Nlm_ErrUserDelete PROTO((ErrStrId magic_cookie));
  224. void LIBCALL Nlm_ErrUserClear PROTO((void));
  225. int LIBCALL ErrSetLogLevel PROTO((ErrSev level));
  226. int LIBCALL ErrGetLogLevel PROTO((void));
  227. int LIBCALL ErrSetMessageLevel PROTO((ErrSev level));
  228. int LIBCALL ErrGetMessageLevel PROTO((void));
  229. int LIBCALL ErrSetFatalLevel PROTO((ErrSev level));
  230. int LIBCALL ErrGetFatalLevel PROTO((void));
  231. unsigned long LIBCALL ErrSetOptFlags PROTO((unsigned long flags));
  232. unsigned long LIBCALL ErrClearOptFlags PROTO((unsigned long flags));
  233. unsigned long LIBCALL ErrTestOptFlags PROTO((unsigned long flags));
  234. void LIBCALL ErrSaveOptions PROTO((ErrOpts *opts)); 
  235. void LIBCALL ErrRestoreOptions PROTO((const ErrOpts *opts));
  236.  
  237. /* Error Option (EO) flags */
  238. #define EO_LOG_SEVERITY  0x00000001L
  239. #define EO_LOG_CODES     0x00000002L
  240. #define EO_LOG_FILELINE  0x00000004L
  241. #define EO_LOG_USERSTR   0x00000008L
  242. #define EO_LOG_ERRTEXT   0x00000010L
  243. #define EO_LOG_MSGTEXT   0x00000020L
  244. #define EO_MSG_SEVERITY  0x00000100L
  245. #define EO_MSG_CODES     0x00000200L
  246. #define EO_MSG_FILELINE  0x00000400L
  247. #define EO_MSG_USERSTR   0x00000800L
  248. #define EO_MSG_ERRTEXT   0x00001000L
  249. #define EO_MSG_MSGTEXT   0x00002000L
  250. #define EO_LOGTO_STDOUT  0x00010000L
  251. #define EO_LOGTO_STDERR  0x00020000L
  252. #define EO_LOGTO_TRACE   0x00040000L
  253. #define EO_LOGTO_USRFILE 0x00080000L
  254. #define EO_XLATE_CODES   0x01000000L
  255. #define EO_WAIT_KEY      0x02000000L
  256. #define EO_PROMPT_ABORT  0x04000000L
  257. #define EO_BEEP          0x08000000L
  258.  
  259. #define EO_ALL_FLAGS     0x0F0F3F3FL
  260.  
  261. #define EO_SHOW_SEVERITY (EO_LOG_SEVERITY | EO_MSG_SEVERITY)
  262. #define EO_SHOW_CODES    (EO_LOG_CODES | EO_MSG_CODES)
  263. #define EO_SHOW_FILELINE (EO_LOG_FILELINE | EO_MSG_FILELINE)
  264. #define EO_SHOW_USERSTR  (EO_LOG_USERSTR | EO_MSG_USERSTR)
  265. #define EO_SHOW_ERRTEXT  (EO_LOG_ERRTEXT | EO_MSG_ERRTEXT)
  266. #define EO_SHOW_MSGTEXT  (EO_LOG_MSGTEXT | EO_MSG_MSGTEXT)
  267.  
  268. #define EO_DEFAULTS      (EO_SHOW_SEVERITY | EO_LOG_CODES | EO_XLATE_CODES | \
  269.                 EO_SHOW_USERSTR | EO_SHOW_ERRTEXT)
  270.  
  271. /* flags for ErrSetLogfile */
  272. #define ELOG_APPEND         0x00000001
  273. #define ELOG_BANNER      0x00000002
  274. #define ELOG_NOCREATE    0x00000004
  275.  
  276. #define ErrSetHandler Nlm_ErrSetHandler
  277. #define ErrUserInstall Nlm_ErrUserInstall
  278. #define ErrUserDelete  Nlm_ErrUserDelete
  279. #define ErrUserClear   Nlm_ErrUserClear
  280. #define ErrSetLogfile   Nlm_ErrSetLogfile
  281. #define ErrSetLog(x)  Nlm_ErrSetLogfile((x),ELOG_BANNER|ELOG_APPEND)
  282.  
  283. /***************************************************************************\
  284. |                               DEBUGGING                                   |
  285. \***************************************************************************/
  286. void LIBCALL Nlm_AssertionFailed PROTO((const char*, const char*,const char*,int));
  287. void LIBCALL Nlm_TraceStr PROTO((const char*));
  288. void CDECL   Nlm_Trace VPROTO((const char*, ...));
  289. void LIBCALL Nlm_AbnormalExit PROTO((int));
  290.  
  291. #define AbnormalExit  Nlm_AbnormalExit
  292.  
  293. #ifdef _DEBUG
  294.  
  295. #ifndef TRACE                        
  296. #define TRACE    Nlm_Trace
  297. #endif
  298. #ifndef ASSERT
  299. #define ASSERT(expr)  ((expr) ? \
  300.     (void)0 : Nlm_AssertionFailed(#expr,THIS_MODULE,THIS_FILE,__LINE__))
  301. #endif
  302. #ifndef VERIFY
  303. #define VERIFY(expr)  ASSERT(expr)
  304. #endif
  305.  
  306. #else /* ! _DEBUG */
  307.  
  308. #ifndef TRACE
  309. #define TRACE    1 ? (void)0 : Nlm_Trace
  310. #endif
  311. #ifndef ASSERT
  312. #define ASSERT(expr)    ((void)0)
  313. #endif
  314. #ifndef VERIFY
  315. #define VERIFY(expr)    ((void)(expr))
  316. #endif
  317.  
  318. #endif  /* ! _DEBUG */
  319.  
  320. /********************* OBSOLETE STUFF BELOW THIS LINE **********************/
  321.  
  322. /* actopt codes */
  323. #define ERR_CONTINUE  1
  324. #define ERR_IGNORE    2
  325. #define ERR_ADVISE    3
  326. #define ERR_ABORT     4
  327. #define ERR_PROMPT    5
  328. #define ERR_TEE       6
  329.  
  330. /* logopt codes */
  331. #define ERR_LOG_ON    1
  332. #define ERR_LOG_OFF   2
  333.  
  334. void LIBCALL Nlm_ErrGetOpts PROTO((short * actopt, short * logopt));
  335. void LIBCALL Nlm_ErrSetOpts PROTO((short actopt, short logopt));
  336. #define ErrGetOpts  Nlm_ErrGetOpts
  337. #define ErrSetOpts  Nlm_ErrSetOpts
  338.  
  339. /* error context codes */
  340. #define CTX_DEBUG      0
  341. #define CTX_UNKNOWN    1
  342. #define CTX_ERRNO      2
  343. #define CTX_NCBICORE   64
  344. #define CTX_NCBIASN1   65
  345. #define CTX_NCBICD       66
  346. #define CTX_NCBIOBJ    67
  347. #define CTX_NCBILMA    68
  348. #define CTX_NCBIGBPARSE 69
  349. #define CTX_NCBIPIRPARSE 70
  350. #define CTX_NCBI2GB    71
  351. #define CTX_NCBIBB2ASN 72
  352. #define CTX_NCBIMATH   73
  353. #define CTX_NCBIMED2ASN 74
  354. #define CTX_NCBISEQENTRY 75
  355. #define CTX_NCBISEQPORT   200
  356. #define CTX_NCBIIDLOAD 300
  357. #define CTX_NCBIIDPROCESS 301
  358. #define CTX_NCBIIDRETRIEVE 302
  359. #define CTX_NCBIAUTHINPARSE 303
  360. #define CTX_KB2ASN 304
  361.  
  362. #define CTX_RESERVED   10000
  363. /* context codes > 10000 are available for application use */
  364. #define CTX_USER       32767    /* default user application context */
  365.  
  366. /* error codes for CTX_NCBICORE */
  367. #define CORE_UNKNOWN    1
  368. #define CORE_NULLPTR    2    /* NULL pointer passed as an argument */
  369. #define CORE_NULLHND    3    /* NULL handle passed as an argument */
  370. #define CORE_MEMORY     4    /* Memory allocation failure */
  371. #define CORE_BAD_COOKIE 5    /* ErrPost User install misused */
  372. #define CORE_BAD_SGML   6    /* SGML entity or range error */
  373.  
  374. #define CORE_FILE_ACCESS  10  /* Error accessing file */
  375. #define CORE_FILE_CREATE  11  /* Error creating file */
  376. #define CORE_FILE_OPEN    12  /* Error opening file */
  377. #define CORE_FILE_READ    13  /* Error reading file */
  378. #define CORE_FILE_WRITE   14  /* Error writing file */
  379. #define CORE_FILE_ERROR   15  /* any other file I/O error */
  380.  
  381. #define ERRPOST(x)    \
  382.     Nlm_ErrSetContext(THIS_MODULE,THIS_FILE,__LINE__,DBFLAG), \
  383.     Nlm_ErrPost x
  384.  
  385. #define Nlm_ErrSetLog(x)  Nlm_ErrSetLogfile((x),ELOG_BANNER|ELOG_APPEND)
  386.  
  387. #define EO_LOG_STDOUT  EO_LOGTO_STDOUT
  388. #define EO_LOG_STDERR  EO_LOGTO_STDERR
  389. #define EO_LOG_TRACE   EO_LOGTO_TRACE 
  390. #define EO_LOG_USRFILE EO_LOGTO_USRFILE
  391.  
  392. #ifdef __cplusplus
  393. }
  394. #endif
  395.  
  396. #endif
  397.